package com.sun.util;

import java.util.Random;

/**
 * @author SunRui
 * @description 验证码
 * @date 2024/7/4 21:16
 */
public class CaptchaUtil {
    //随机验证码
    public static String generateCaptcha() {
        Random random = new Random();
        StringBuilder captcha = new StringBuilder();
        for (int i = 0; i < 4; i++) {
            captcha.append(random.nextInt(10));
        }
        return captcha.toString();
    }
    //验证码校验
    public boolean captchaEquals(String captcha1,String captcha2) {
        if (!captcha2.equals(captcha1)){
            return false;
        }
        return true;
    }
}
